<template>
  <div class="edit">
    <el-dialog :visible.sync="dialogVisible" center class="countDialog" :close-on-click-modal="false" @close="resetO('ruleForm')">
      <div slot="title" class="dialog-title">{{ pageTitle }}</div>
      <div>
        <el-form ref="ruleForm" :rules="rules" :model="form" size="medium" label-width="100px">
          <el-form-item prop="app_id" label="APPID">
            <el-input v-model="form.app_id" placeholder="输入APPID"></el-input>
          </el-form-item>
          <el-form-item prop="name" label="APP名称">
            <el-input v-model="form.name" placeholder="输入APP名称"></el-input>
          </el-form-item>
          <el-form-item prop="advId" label="所属广告主">
            <el-select v-model="form.advId" :disabled="(form.id != undefined && form.advId != '' && form.advId != undefined )" placeholder="请选择">
              <el-option v-for="item in adx_all" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="pkg" label="包名">
            <el-input v-model="form.pkg" placeholder="输入包名"></el-input>
          </el-form-item>
          <el-form-item prop="icon" label="icon地址">
            <el-input v-model="form.icon" placeholder="输入icon地址"></el-input>
          </el-form-item>
          <el-form-item prop="size" label="包大小">
            <el-input-number :min="0" :max="10000000000" :controls="false" v-model="form.size" placeholder="输入包大小"></el-input-number>
          </el-form-item>
          <el-form-item prop="ver" label="版本号">
            <el-input v-model="form.ver" placeholder="输入版本号"></el-input>
          </el-form-item>
          <el-form-item prop="dev" label="开发者">
            <el-input v-model="form.dev" placeholder="输入开发者"></el-input>
          </el-form-item>
          <el-form-item prop="pri" label="隐私链接">
            <el-input v-model="form.pri" placeholder="输入隐私链接"></el-input>
          </el-form-item>
          <el-form-item prop="per" label="权限链接">
            <el-input v-model="form.per" placeholder="输入权限链接"></el-input>
          </el-form-item>
          <el-form-item prop="furl" label="功能地址">
            <el-input v-model="form.furl" placeholder="输入功能地址"></el-input>
          </el-form-item>
          <el-form-item prop="fstr" label="功能说明">
            <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="form.fstr"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" @click="onSubmit('ruleForm')">提交</el-button>
            <el-button size="small" @click="resetO('ruleForm')">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {dsp_adv_app_add, dsp_adv_app_edit} from '@/api/dsp_adv_app'
import {dsp_adv_all} from '@/api/dsp_advertiser'
export default {
  name: 'dsp_adv_app-edit',
  data(){
    return {
      dialogVisible: false,
      pageTitle:'新增',
      form:{},
      adx_all:[],
      rules:{
        name:[
          {required: true, message: '请输入名称', trigger: 'blur'}
        ],
        adx_id:[
          {required: true, message: '请选择广告主', trigger: 'blur'}
        ]
      }
    }
  },
  computed: {
  },
  components: {

  },
  mounted(){
  },
  created() {
  },
  methods: {
    getall(){
      dsp_adv_all({}).then(res => {
        var data = res.data
        console.log(data)
        this.adx_all = data
      }).catch(err => {
        console.log(err)
      })
    },
    resetO(formName){
      this.dialogVisible = false
      this.form = {}
      this.$refs[formName].resetFields()
      //调用父组件方法
      this.$parent.GetList()
    },
    onSubmit(formName){
      var sdata = this.form
      sdata.flag = parseInt(sdata.flag)

      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.SObj(sdata).then(res => {
            var data = res.data
            console.log(data)
            this.$message({
              showClose: true,
              center:true,
              message: '操作成功',
              type: 'success'
            })
            this.dialogVisible = false
            this.$parent.GetList()
          }).catch(err => {
            console.log(err)
          })
        }else {
          return false
        }
      })

    },
    SObj(sdata){
      if (sdata.id == undefined || sdata.id == ''){
        return dsp_adv_app_add(sdata)
      }else {
        return dsp_adv_app_edit(sdata)
      }
    },
    showInfo(info){
      this.dialogVisible = true
      if (info.id != undefined) {
        this.pageTitle = '编辑'
        this.form = info
      }else {
        this.form = {}
      }
      this.getall()
    }
  }
}
</script>
<style lang="scss" scoped>
.edit {

}
</style>